home *** CD-ROM | disk | FTP | other *** search
/ BMUG PD-ROM 1995 Fall / PD-ROM F95.toast / Programming / Programming Utilities / RedLetters ƒ / RedLetters.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-01  |  2.4 KB  |  148 lines  |  [TEXT/ttxt]

  1. #include <Palette.h>
  2.  
  3. /************************************
  4.  *                                    *
  5.  *    RedLetters    --    by Kenneth Lu    *
  6.  *                                    *
  7.  *         (Kenneth_K._Lu@BMUG.org)    *
  8.  *                                    *
  9.  *                           5/1/94    *
  10.  *                                    *
  11.  ************************************/
  12.  
  13.  
  14. int TheBitDepth(WindowPtr theWindow);
  15.  
  16. main()
  17. {
  18.     RGBColor        c;
  19.     long            i, j, k, oldTicks;
  20.     Boolean            down;
  21.     PaletteHandle    pal;
  22.     WindowPtr        window;
  23.     Rect            r;
  24.     char            s[11] = {"REDLETTERS"};
  25.     CTabHandle        cTab;
  26.     ColorSpec        cSpecs[16];
  27.     EventRecord        e;
  28.     
  29.     ToolBoxInit();
  30.     
  31.     SetRect(&r, 100, 100, 275, 140);
  32.     window = NewCWindow(NULL, &r, "\pRedLetters", TRUE, noGrowDocProc, MOVE_FRONT, TRUE, 0L);
  33.     SetPort(window);
  34.     
  35.     FillRect(&(window->portRect), black);
  36.     
  37.     k = TheBitDepth(window);
  38.     if ( !((k == 4) || (k == 8)) )
  39.     {
  40.         ShowCursor();
  41.         Alert(BASE_ID, NULL);
  42.         ExitToShell();
  43.     }
  44.     
  45.     pal = NewPalette(256, NULL, pmAnimated, 0x0000);
  46.     c.green = 0;
  47.     c.blue = 0;
  48.     
  49.     for(i=0; i<16; i++)
  50.     {
  51.         c.red = i*16*65535/240;
  52.         SetEntryColor(pal, i, &c);
  53.     }
  54.     
  55.     SetPalette(window, pal, TRUE);
  56.     
  57.     TextFont(newYork);
  58.     TextFace(bold);
  59.     TextSize(24);
  60.     
  61.     for(i=0,j=9; i<10; i++,j--)
  62.     {
  63.         MoveTo(10+(i*16), 30);
  64.         PmForeColor(j);
  65.         DrawChar(s[i]);
  66.     }
  67.     
  68.     i=0;
  69.     
  70.     cTab=(CTabHandle)NewHandle(8+(16*8));
  71.     HLock((Handle)cTab);
  72.     (**cTab).ctSeed = GetCTSeed();
  73.     (**cTab).ctSize = 15;
  74.     
  75.     while(TRUE)
  76.     {
  77.         oldTicks = Ticks;
  78.         for (j=0; j<16; j++)
  79.         {
  80.             if (down)
  81.                 k=i-j;
  82.             else
  83.                 k=i+j;
  84.             if (down && (k<0))
  85.                 k = -k;
  86.             else if (k>15)
  87.                 k = 15-(k-15);
  88.             c.red = k*16*65535/240;
  89.             (**cTab).ctTable[j].value = j;
  90.             (**cTab).ctTable[j].rgb = c;
  91. //            AnimateEntry (window, j, &c);
  92.         }
  93.  
  94.         
  95.         AnimatePalette (window, cTab, 0, 0, 16);
  96.         
  97.         if (down)
  98.             i--;
  99.         else
  100.             i++;
  101.         if (i>15)
  102.         {
  103.             down = TRUE;
  104.             i -= 2;
  105.         }
  106.         if (i<0)
  107.         {
  108.             down = FALSE;
  109.             i += 2;
  110.         }
  111.         if (WaitNextEvent (mDownMask, &e, 0, NULL))
  112.         {
  113.             k = FindWindow(e.where, &window);
  114.             if (k = inGoAway)
  115.                 if (TrackGoAway (window, e.where))
  116.                     ExitToShell();
  117.                 
  118.         }
  119.         while (oldTicks+3>Ticks);
  120.     }
  121.     HUnlock((Handle)cTab);
  122. }
  123.  
  124. /******************* ToolBoxInit ***********/
  125.  
  126. ToolBoxInit()
  127. {
  128.     InitGraf(&thePort);
  129.     InitFonts();
  130.     FlushEvents(everyEvent, 0);
  131.     InitWindows();
  132.     InitMenus();
  133.     TEInit();
  134.     InitDialogs(NULL);
  135.     InitCursor();
  136. }
  137.  
  138. /********* TheBitDepth ***********/
  139.  
  140. int TheBitDepth(WindowPtr theWindow)
  141. {
  142.     PixMapHandle    thePixMap;
  143.     
  144.     thePixMap = ((CWindowPtr)theWindow)->portPixMap;
  145.     return ((**thePixMap).pixelSize);
  146. }
  147.  
  148.